﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAO_DTO_WS.DTO;
using DAO_DTO_WS.DAO;

namespace LayoutTemplate
{
    public partial class Default : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                if (Session["ID"] == null || Session["ID"].ToString() == "")
                {
                    tbemail.Enabled = true;
                    btnDangKy.Enabled = true;
                }
                else
                {
                    tbemail.Text = "email@yahoo.com";
                    tbemail.Enabled = false;
                    btnDangKy.Enabled = false;
                }
            }
        }

        protected void btnDangKy_Click(object sender, EventArgs e)
        {
            NhanTinKhuyenMaiDTO nhantin = new NhanTinKhuyenMaiDTO();
            string tendiaphuong = radio.SelectedValue;
            nhantin.Email = tbemail.Text.Trim();
           
            if (string.Compare(tendiaphuong, "Ha Noi", false) != 0)
                nhantin.MaDiaPhuong = 1;
            else nhantin.MaDiaPhuong = 2;
            if ((nhantin.Email != string.Empty) && (!NhanTinKhuyenMaiDAO.KiemTraEmail(nhantin.Email)))
            {
                NhanTinKhuyenMaiDAO.ThemEmail(nhantin);
                
                lb1.Text = "Dang Ki Thanh Cong";
                Response.Redirect("TrangChu.aspx");
            }
            else Response.Redirect("TrangLoi.aspx?Error=3");
        }
    }
}
